package com.bsh.service.impl;


import com.bsh.entity.Bo.TbClass;
import com.bsh.entity.Bo.TbScore;
import com.bsh.entity.Dto.ClassChineseScoreSummary;
import com.bsh.entity.Dto.ClassStudentTotalScore;
import com.bsh.entity.Dto.StudentDTO;
import com.bsh.entity.Dto.StudentScoreSummary;
import com.bsh.mapper.TbScoreMapper;
import com.bsh.mapper.TbStudentMapper;
import com.bsh.mapper.TbClassMapper;
import com.bsh.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private TbStudentMapper tbStudentMapper;

    @Resource
    private TbClassMapper tbClassMapper;

    @Resource
    private TbScoreMapper tbScoreMapper;


    /**
     * 查询学生清单
     *
     * @param pageIndex 页码
     * @param pageSize  条数
     * @return PageInfo<StudentDTO>
     */
    @Override
    public PageInfo<StudentDTO> getStudentsList(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        return new PageInfo<>(tbStudentMapper.getStudentsList());
    }


    /**
     * @param pageIndex 页码
     * @param pageSize  条数
     * @return 查询结果
     * 使用pageHelper 进行分页查询。
     */
    @Override
    public PageInfo<StudentDTO> getFilteredStudents(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<StudentDTO> filteredStudents = tbStudentMapper.getFilteredStudents();
        return new PageInfo<>(filteredStudents);
    }

    /**
     * @param pageIndex 页码
     * @param pageSize  条数
     * @return PageInfo<ClassChineseScoreSummary>
     */
    @Override
    public PageInfo<ClassChineseScoreSummary> getChineseScoreSummary(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        return new PageInfo<>(tbClassMapper.getChineseScoreSummary(pageIndex, pageSize));
    }

    @Override
    public PageInfo<ClassStudentTotalScore> getStudentTotalScoreByTeacher(String teacherName, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        return new PageInfo<>(tbClassMapper.getStudentTotalScoreByTeacher(teacherName, pageIndex, pageSize));
    }

    @Override
    public PageInfo<StudentScoreSummary> getStudentScoreSummary(Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        return new PageInfo<>(tbScoreMapper.getStudentScoreSummary(pageIndex, pageSize));
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertClass(TbClass tbClass) {

        tbClassMapper.insert(tbClass);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertScore(TbScore tbScore) {
        tbScoreMapper.insert(tbScore);
    }

    @Override
    public void deleteClassById(Integer id) {

    }

}
